//
//  ApplyOilThirdVC.m
//  Base_App
//
//  Created by Yutian Duan on 2019/6/18.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "ApplyOilThirdVC.h"
#import "ApplyFourthVC.h"
#import "ApplyeOilHeadView.h"
#import "YFBaseTextField.h"


@interface ApplyOilThirdVC () <UITextFieldDelegate>

@property (nonatomic, strong) ApplyeOilHeadView *stepHeadView;
@property (nonatomic, strong) UIScrollView *contenView;
@property (nonatomic, strong) NSMutableArray <YFBaseTextField *>*textFieldArray;
@property (nonatomic, strong) UIImageView *signImageView;
@property (nonatomic, strong) UIButton *agreedButton;
///
@property (nonatomic, strong) UILabel *dateLabel;
///! 当前时间搓
@property (nonatomic, strong) NSDate *nowDate;

@end

@implementation ApplyOilThirdVC

- (void)viewDidLoad {
  [super viewDidLoad];
  
}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  //  [self setDefaltNavBar];
  [self.navigationController setNavigationBarHidden:NO animated:animated];
  [self setNavImage:[UIImage imageNamed:@"Home_BgImage"] titleColor:[UIColor whiteColor]];
  [self setStatusBarStyleWhite];
  
}


- (void)createFields {
  [super createFields];
  self.navigationItem.title = YTLocalizedString(@"油咭申请");
  [self createWhiteBack];
  _textFieldArray = [[NSMutableArray alloc] init];
}

- (void)createViews {
  
  [super createViews];
  
  _contenView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, NavBarHeight, ScreenWidth, ScreenHeight - NavBarHeight - 50)];
  [self.view addSubview:_contenView];
  
  _stepHeadView = [[ApplyeOilHeadView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth * ITEMPRO)];
  _stepHeadView.stepCount = 2;
  _stepHeadView.userInteractionEnabled = NO;
  _stepHeadView.isPersonal = _applyModel.isPersonal;
  [_contenView addSubview:_stepHeadView];
  
  [self createCarTip];
  [self createButton];
  
}

- (void)createCarTip {
  
  
  
  UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, _stepHeadView.yt_bottom + 15, _contenView.yt_width - 30, 30)];
  titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
  titleLabel.textColor = [UIColor blackColor];
  titleLabel.textAlignment = NSTextAlignmentLeft;
  titleLabel.text = YTLocalizedString(@"信用咭及付款授权书");
  [_contenView addSubview:titleLabel];

  UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, titleLabel.yt_bottom + 0, _contenView.yt_width - 60, 0)];
  tipLabel.font = [UIFont systemFontOfSize:9.0f];
  tipLabel.textColor = DEF_BLACK;
  tipLabel.numberOfLines = 0;
  [_contenView addSubview:tipLabel];
  tipLabel.text = YTLocalizedString(@"恒堡会目标");
  [tipLabel sizeToFit];
  
  UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(15, tipLabel.yt_bottom + 20, _contenView.yt_width - 30, 0.8)];
  lineView.backgroundColor = DEF_GRAY;
  [_contenView addSubview:lineView];
  
  
  ///! 信用卡
  UILabel *cardTypeLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, lineView.yt_bottom + 20, 80, 30)];
  cardTypeLabel.text = [NSString stringWithFormat:@"%@:",YTLocalizedString(@"信用咭号码")];
  cardTypeLabel.font = [UIFont systemFontOfSize:11.0];
  cardTypeLabel.textAlignment = NSTextAlignmentLeft;
  [_contenView addSubview:cardTypeLabel];
  
  UIImageView *logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(cardTypeLabel.yt_right, cardTypeLabel.yt_top, 100, cardTypeLabel.yt_height)];
  logoImageView.image = [UIImage imageNamed:@"Oil_Card_logo"];
  [_contenView addSubview:logoImageView];
  
  
  CGFloat fieldW = (_contenView.yt_width - 120)/4;
  
  YFBaseTextField *tempField = nil;
  
  for (NSInteger i = 0; i < 4; i ++) {
    YFBaseTextField *firstField = [[YFBaseTextField alloc] initWithFrame:CGRectMake(60, cardTypeLabel.yt_bottom + 10, fieldW - 5, 30)];
    firstField.placeholder = @"8888";
    firstField.textAlignment = NSTextAlignmentCenter;
    [firstField setTextFont:[UIFont systemFontOfSize:12]];
    [firstField set_placeTextColor:DEF_GRAY];
    firstField.layer.masksToBounds = YES;
    firstField.layer.cornerRadius = 8;
    firstField.backgroundColor = [UIColor whiteColor];

    if (tempField != nil) {
      firstField.yt_left = tempField.yt_right + 10;
    }
    tempField = firstField;
    [_contenView addSubview:firstField];
    [_textFieldArray addObject:firstField];
  }
  
  
  ///! 发卡银行
  UILabel *sendBankLabel = [[UILabel alloc] initWithFrame:CGRectMake(cardTypeLabel.yt_left, tempField.yt_bottom + 10, cardTypeLabel.yt_width, cardTypeLabel.yt_height)];
  sendBankLabel.text = [NSString stringWithFormat:@"%@:",YTLocalizedString(@"发咭银行")];
  sendBankLabel.font = cardTypeLabel.font;
  sendBankLabel.textAlignment = cardTypeLabel.textAlignment;
  sendBankLabel.textColor = cardTypeLabel.textColor;
  [_contenView addSubview:sendBankLabel];
  
  YFBaseTextField *sendCardTextField = [[YFBaseTextField alloc] initWithFrame:CGRectMake(sendBankLabel.yt_right, sendBankLabel.yt_top, _contenView.yt_width - sendBankLabel.yt_right -  60 + 10, sendBankLabel.yt_height)];
  sendCardTextField.delegate = self;
  sendCardTextField.placeholder = YTLocalizedString(@"选择信用咭发咭银行");
  [sendCardTextField setTextFont:[UIFont systemFontOfSize:12]];
  [sendCardTextField set_placeTextColor:DEF_GRAY];
  sendCardTextField.layer.masksToBounds = YES;
  sendCardTextField.layer.cornerRadius = 8;
  sendCardTextField.backgroundColor = [UIColor whiteColor];
  sendCardTextField.leftViewMode = UITextFieldViewModeAlways;
  sendCardTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, sendCardTextField.yt_height)];
  
  sendCardTextField.rightViewMode = UITextFieldViewModeAlways;
  UIImageView *redArrowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 12)];
//  redArrowImageView.contentMode = UIViewContentModeLeft;
  redArrowImageView.image = [UIImage imageNamed:@"Oil_card_redArrow"];
  sendCardTextField.rightView = redArrowImageView;
  [_contenView addSubview:sendCardTextField];
  [_textFieldArray addObject:sendCardTextField];
  
  
  
  //! 有效期
  UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(sendBankLabel.yt_left, sendBankLabel.yt_bottom + 10, sendBankLabel.yt_width, sendBankLabel.yt_height)];
  dateLabel.text = [NSString stringWithFormat:@"%@:",YTLocalizedString(@"有效期至")];
  dateLabel.font = cardTypeLabel.font;
  dateLabel.textAlignment = cardTypeLabel.textAlignment;
  dateLabel.textColor = cardTypeLabel.textColor;
  [_contenView addSubview:dateLabel];
  
  CGFloat monthW = (sendCardTextField.yt_width  - 30)/2 - 20;
  
  YFBaseTextField *monthField = [[YFBaseTextField alloc] initWithFrame:CGRectMake(dateLabel.yt_right, dateLabel.yt_top,monthW, dateLabel.yt_height)];
  monthField.delegate = self;
  monthField.placeholder = YTLocalizedString(@"MM");
  [monthField setTextFont:[UIFont systemFontOfSize:12]];
  [monthField set_placeTextColor:DEF_GRAY];
  monthField.layer.masksToBounds = YES;
  monthField.layer.cornerRadius = 8;
  monthField.backgroundColor = [UIColor whiteColor];
  monthField.leftViewMode = UITextFieldViewModeAlways;
  monthField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, monthField.yt_height)];

  monthField.rightViewMode = UITextFieldViewModeAlways;
  UIImageView *redArrowImageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 12)];
  redArrowImageView1.image = [UIImage imageNamed:@"Oil_card_redArrow"];
  monthField.rightView = redArrowImageView1;
  [_contenView addSubview:monthField];
  [_textFieldArray addObject:monthField];
  
  
  YFBaseTextField *yearField = [[YFBaseTextField alloc] initWithFrame:CGRectMake(monthField.yt_right + 10, monthField.yt_top,monthW + 20, monthField.yt_height)];
  yearField.delegate = self;
  yearField.placeholder = YTLocalizedString(@"YYYY");
  [yearField setTextFont:[UIFont systemFontOfSize:12]];
  [yearField set_placeTextColor:DEF_GRAY];
  yearField.layer.masksToBounds = YES;
  yearField.layer.cornerRadius = 8;
  yearField.backgroundColor = [UIColor whiteColor];
  yearField.leftViewMode = UITextFieldViewModeAlways;
  yearField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, yearField.yt_height)];
  
  yearField.rightViewMode = UITextFieldViewModeAlways;
  UIImageView *redArrowImageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 12)];
  redArrowImageView2.image = [UIImage imageNamed:@"Oil_card_redArrow"];
  yearField.rightView = redArrowImageView2;
  [_contenView addSubview:yearField];
  [_textFieldArray addObject:yearField];

  ///! 英文名字
  UILabel *enNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(dateLabel.yt_left, dateLabel.yt_bottom + 10, dateLabel.yt_width, dateLabel.yt_height)];
  enNameLabel.text = [NSString stringWithFormat:@"%@:",YTLocalizedString(@"英文姓名")];
  enNameLabel.font = cardTypeLabel.font;
  enNameLabel.textAlignment = cardTypeLabel.textAlignment;
  enNameLabel.textColor = cardTypeLabel.textColor;
  [_contenView addSubview:enNameLabel];
  
  YFBaseTextField *enNameField = [[YFBaseTextField alloc] initWithFrame:CGRectMake(enNameLabel.yt_right, enNameLabel.yt_top, sendCardTextField.yt_width, sendCardTextField.yt_height)];
  enNameField.placeholder = YTLocalizedString(@"输入持咭人英文姓名");
  [enNameField setTextFont:[UIFont systemFontOfSize:12]];
  [enNameField set_placeTextColor:DEF_GRAY];
  enNameField.layer.masksToBounds = YES;
  enNameField.layer.cornerRadius = 8;
  enNameField.backgroundColor = [UIColor whiteColor];
  enNameField.leftViewMode = UITextFieldViewModeAlways;
  enNameField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, enNameField.yt_height)];
  [_contenView addSubview:enNameField];
  [_textFieldArray addObject:enNameField];
  
  
  UIView *signContentView = [[UIView alloc] initWithFrame:CGRectMake(0, enNameField.yt_bottom + 10, _contenView.yt_width, _contenView.yt_width/3.2)];
  signContentView.userInteractionEnabled = YES;
  [_contenView addSubview:signContentView];

           
  ///签名
  _signImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, signContentView.yt_width, signContentView.yt_height)];
  _signImageView.backgroundColor = [UIColor whiteColor];
  _signImageView.userInteractionEnabled = YES;
  UITapGestureRecognizer *tapSingle = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(signClick)];
  [_signImageView addGestureRecognizer:tapSingle];
  [signContentView addSubview:_signImageView];
  
  UIImageView *sign_tipImageView = [[UIImageView alloc] initWithFrame:CGRectMake(30, _signImageView.yt_bottom - 50, 20, 20)];
  sign_tipImageView.image = [UIImage imageNamed:@"Oil_Sign_Tip"];
  [signContentView addSubview:sign_tipImageView];
  
  UILabel *sign_tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(sign_tipImageView.yt_right + 10, sign_tipImageView.yt_top, 100, sign_tipImageView.yt_height)];
  sign_tipLabel.textAlignment = NSTextAlignmentLeft;
  sign_tipLabel.font = [UIFont systemFontOfSize:11.0f];
  sign_tipLabel.textColor = DEF_GRAY;
  sign_tipLabel.text = YTLocalizedString(@"持咭人签署");
  [signContentView addSubview:sign_tipLabel];
  
  UIImageView *lineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(sign_tipImageView.yt_left, sign_tipImageView.yt_bottom, _signImageView.yt_width - sign_tipImageView.yt_left * 2, 1)];
//  lineImageView.backgroundColor = [UIColor redColor];
  lineImageView.image = [UIImage imageNamed:@"Oil_Sign_Line"];
  [signContentView addSubview:lineImageView];
  
  _dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, lineImageView.yt_bottom, 100, 30)];
  _dateLabel.textColor = sign_tipLabel.textColor;
  _dateLabel.font = sign_tipLabel.font;
  _dateLabel.textAlignment = NSTextAlignmentRight;
  _dateLabel.yt_right = lineView.yt_right;
  _dateLabel.text = YTLocalizedString(@"2019/03/06");
  [signContentView addSubview:_dateLabel];
  
  
  ///! 信用卡授权书
  UILabel *powerLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleLabel.yt_left, signContentView.yt_bottom + 10, titleLabel.yt_width, titleLabel.yt_height)];
  powerLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
  powerLabel.textColor = [UIColor blackColor];
  powerLabel.textAlignment = NSTextAlignmentLeft;
  powerLabel.text = YTLocalizedString(@"信用咭及付款授权书");
  [_contenView addSubview:powerLabel];

  
  UITextView *bookTextView = [[UITextView alloc] initWithFrame:CGRectMake(30, powerLabel.yt_bottom+10, _contenView.yt_width - 60, 100)];
  bookTextView.font = tipLabel.font;
  bookTextView.textColor = DEF_BLACK;
  bookTextView.backgroundColor = [UIColor clearColor];
  [_contenView addSubview:bookTextView];
  NSString *powerStr = YTLocalizedString(@"信用卡授权协议");
  bookTextView.text = powerStr;
  

  _agreedButton = [[UIButton alloc] initWithFrame:CGRectMake(30, bookTextView.yt_bottom + 10, 15, 15)];
  [_agreedButton setImage:[UIImage imageNamed:@"Oil_card_notagreed"] forState:UIControlStateNormal];
  [_agreedButton setImage:[UIImage imageNamed:@"Oil_card_agreed"] forState:UIControlStateSelected];
  [_contenView addSubview:_agreedButton];
  _agreedButton.selected = NO;
  [_agreedButton addTarget:self action:@selector(agreedClick) forControlEvents:UIControlEventTouchUpInside];
  
  UILabel *agreedLabel = [[UILabel alloc] initWithFrame:CGRectMake(_agreedButton.yt_right + 5, _agreedButton.yt_top, _contenView.yt_width - _agreedButton.yt_right - 30, 0)];
  agreedLabel.font = bookTextView.font;
  agreedLabel.textColor = DEF_BLACK;
  agreedLabel.numberOfLines = 0;
  [_contenView addSubview:agreedLabel];
  
  agreedLabel.text = YTLocalizedString(@"恒堡会授权同意");
  [agreedLabel sizeToFit];
  
  _contenView.contentSize = CGSizeMake(ScreenWidth, agreedLabel.yt_bottom + 20);
  
}

- (void)createButton {
  ///! 取消
  UIButton *cancelButton = [[UIButton alloc] initWithFrame:CGRectMake(0, _contenView.yt_bottom + 10, 30 * 5, 30)];
  [cancelButton setTitle:YTLocalizedString(@"上一步") forState:UIControlStateNormal];
  cancelButton.backgroundColor = DEF_GRAY;
  cancelButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
  [cancelButton addTarget:self action:@selector(cancelclick) forControlEvents:UIControlEventTouchUpInside];
  cancelButton.yt_right = self.view.yt_centerX - 5;
  cancelButton.layer.masksToBounds = YES;
  cancelButton.layer.cornerRadius = 8;
  [self.view addSubview:cancelButton];
  
  ///! 下一步
  UIButton *nextStepButton = [[UIButton alloc] initWithFrame:CGRectMake(cancelButton.yt_right + 10, cancelButton.yt_top, cancelButton.yt_width, cancelButton.yt_height)];
  [nextStepButton setTitle:YTLocalizedString(@"下一步") forState:UIControlStateNormal];
  nextStepButton.backgroundColor = DEF_RED;
  nextStepButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
  [nextStepButton addTarget:self action:@selector(nextclick) forControlEvents:UIControlEventTouchUpInside];
  nextStepButton.layer.masksToBounds = YES;
  nextStepButton.layer.cornerRadius = 8;
  [self.view addSubview:nextStepButton];

}

- (void)agreedClick {
  _agreedButton.selected = !_agreedButton.selected;
}

- (void)cancelclick {
  
}


- (void)nextclick {
  ApplyFourthVC *fourthVC = [[ApplyFourthVC alloc] init];
  fourthVC.applyModel = self.applyModel;
  [self.navigationController pushViewController:fourthVC animated:YES];
  
}

- (void)signClick {
  ///! 签名
  
}

#pragma mark - UITextFieldDelegate


@end
